package models.send;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import models.System.Headline.code;
import models.com.chuanglan.sms.request.SmsSendRequest;
import models.com.chuanglan.sms.response.SmsSendResponse;
import models.com.chuanglan.sms.util.ChuangLanSmsUtil;
import play.Logger;

public class sms {
    public String phone;
    public String msg;

    /**
     * @发送短信，获取短信信息
     * @return
     */
    public String SendSMS(){
        //状态报告
        String report= "true";
        if (phone==null){
            return null;
        }
        if (msg==null){
            return null;
        }
        if (phone!=null&&msg!=null){
            Logger.info(code.account+"++++++++++++++"+code.password);
            SmsSendRequest smsSingleRequest = new SmsSendRequest(code.account,code.password, msg, phone,report);

            String requestJson = JSON.toJSONString(smsSingleRequest);

            Logger.info("before request string is: " + requestJson);

            String response = ChuangLanSmsUtil.sendSmsByPost(code.smsSingleRequestServerUrl, requestJson);

            Logger.info("response after request result is :" + response);

            SmsSendResponse smsSingleResponse = JSON.parseObject(response, SmsSendResponse.class);

            Logger.info("response  toString is :" + smsSingleResponse.toString());

           return  smsSingleResponse.toString();
        }

        return  null;
    }



}
